package ddu.com.service;

import com.alibaba.fastjson.JSON;
import com.ddu.common.util.result.RespCode;
import com.ddu.common.util.result.Result;
import com.ddu.common.util.result.ResultUtil;
import ddu.com.facade.entity.User;
import ddu.com.facade.service.IUserService;
import ddu.com.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author:zhangxia
 * @createTime: 2018/4/18 14:47
 * @version:1.0
 * @desc:
 */
@Slf4j
@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    UserMapper userMapper;


    /**
     * @auth: zhangxia
     * @desc: 添加用户
     * @methodName: addUser
     * @params: [user]
     * @return: com.ddu.common.util.result.Result
     * @createTime: 2018/4/27 15:29
     * @version:2.1.6
     */
    @Override
    public Result addUser(User user) {
        log.info("添加用户 service层入参参数user={}", JSON.toJSONString(user));
        Result result = ResultUtil.getResult(RespCode.Code.FAIL);
        try {
            int num = userMapper.insert(user);
            if (num>0){
                result = ResultUtil.getResult(RespCode.Code.SUCCESS);
            }
        } catch (Exception e) {
            log.info("添加用户 service处理异常e={}",e);
        }
        log.info("添加用户 service层处理结果result={}",JSON.toJSONString(result));
        return result;
    }
}
